package com.carAnalysisAdmin.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.carAnalysisAdmin.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.carAnalysisAdmin.system.domain.SysParkFloor;
import com.carAnalysisAdmin.system.mapper.SysParkSpotMapper;
import com.carAnalysisAdmin.system.domain.SysParkSpot;
import com.carAnalysisAdmin.system.service.ISysParkSpotService;

/**
 * 车位Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-14
 */
@Service
public class SysParkSpotServiceImpl implements ISysParkSpotService 
{
    @Autowired
    private SysParkSpotMapper sysParkSpotMapper;

    /**
     * 查询车位
     * 
     * @param id 车位主键
     * @return 车位
     */
    @Override
    public SysParkSpot selectSysParkSpotById(Long id)
    {
        return sysParkSpotMapper.selectSysParkSpotById(id);
    }

    /**
     * 查询车位列表
     * 
     * @param sysParkSpot 车位
     * @return 车位
     */
    @Override
    public List<SysParkSpot> selectSysParkSpotList(SysParkSpot sysParkSpot)
    {
        return sysParkSpotMapper.selectSysParkSpotList(sysParkSpot);
    }

    /**
     * 新增车位
     * 
     * @param sysParkSpot 车位
     * @return 结果
     */
    @Transactional
    @Override
    public Integer insertSysParkSpot(SysParkSpot sysParkSpot)
    {
        Integer queryMaxId = sysParkSpotMapper.queryMaxId(sysParkSpot);
        if (queryMaxId == null) {
            sysParkSpot.setCode(sysParkSpot.getFloorId() + "-" + 1);
        } else {
            sysParkSpot.setCode(sysParkSpot.getFloorId() + "-" + (queryMaxId + 1));
        }
        sysParkSpot.setCode(sysParkSpot.getFloorId()+"-"+(queryMaxId+1));
        Integer rows = sysParkSpotMapper.insertSysParkSpot(sysParkSpot);
//        insertSysParkFloor(sysParkSpot);
        return rows;
    }

    /**
     * 修改车位
     * 
     * @param sysParkSpot 车位
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysParkSpot(SysParkSpot sysParkSpot)
    {
        sysParkSpotMapper.deleteSysParkFloorById(Long.valueOf(sysParkSpot.getId()));
//        insertSysParkFloor(sysParkSpot);
        return sysParkSpotMapper.updateSysParkSpot(sysParkSpot);
    }

    /**
     * 批量删除车位
     * 
     * @param ids 需要删除的车位主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysParkSpotByIds(Long[] ids)
    {
        sysParkSpotMapper.deleteSysParkFloorByIds(ids);
        return sysParkSpotMapper.deleteSysParkSpotByIds(ids);
    }

    /**
     * 删除车位信息
     * 
     * @param id 车位主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysParkSpotById(Long id)
    {
        sysParkSpotMapper.deleteSysParkFloorById(id);
        return sysParkSpotMapper.deleteSysParkSpotById(id);
    }

    @Override
    public int handleUsable(Long[] ids) {
        return sysParkSpotMapper.handleUsable(ids);
    }

    @Override
    public int handleDisabled(Long[] ids) {
        return sysParkSpotMapper.handleDisabled(ids);
    }

    @Override
    public SysParkSpot selectSysParkSpotByCode(String spotCode) {
        return sysParkSpotMapper.selectSysParkSpotByCode(spotCode);
    }

    @Override
    public List selectSysParkSpotByFloor(Long id) {
        return sysParkSpotMapper.selectSysParkSpotByFloor(id);
    }

    /**
     * 新增楼层管理信息
     * 
     * @param sysParkSpot 车位对象
     */
//    public void insertSysParkFloor(SysParkSpot sysParkSpot)
//    {
//        List<SysParkFloor> sysParkFloorList = sysParkSpot.getSysParkFloorList();
//        Integer id = sysParkSpot.getId();
//        if (StringUtils.isNotNull(sysParkFloorList))
//        {
//            List<SysParkFloor> list = new ArrayList<SysParkFloor>();
//            for (SysParkFloor sysParkFloor : sysParkFloorList)
//            {
//                sysParkFloor.setId(id);
//                list.add(sysParkFloor);
//            }
//            if (list.size() > 0)
//            {
//                sysParkSpotMapper.batchSysParkFloor(list);
//            }
//        }
//    }
}
